class Solution:
    def invertTree(self, root: TreeNode) -> TreeNode:
        if not root:  # root == None:
            return root
        left = self.invertTree(root.left)  # 注意递归如何使用，因为要返回所以应该是倒着计算
        right = self.invertTree(root.right)  # 注意类内部函数递归调用的方法
        root.left, root.right = right, left
        return root